Repository navigation
FIX: reload a sending conversation after another one has loaded - #3663
Open
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
Open
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
Conversation
The reload guard skipped any conversation with a send in flight, even when the hook held another conversation's transcript, so returning through the URL kept rendering the other conversation until the send landed. The skip now applies only while the hook still holds the sending conversation's own view. Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
Comment on lines
+185
to
+193
| // A send in flight owns this conversation's optimistic transcript, but only | ||
| // while the hook still holds it. Once another conversation is loaded, the | ||
| // optimistic copy is gone and returning here must load server state rather | ||
| // than keep rendering the other conversation under this URL. | ||
| const holdsAnotherConversation = ( | ||
| loadedConversationIdRef.current !== null | ||
| && loadedConversationIdRef.current !== activeConversationId | ||
| ) | ||
| if (!force && !holdsAnotherConversation && ( |
Contributor
There was a problem hiding this comment.
null means both "lazy creation holds the transcript" and "reset, nothing held", so sending in x/A, visiting attack y, then returning still skips the reload (empty view, no spinner). Could we mark lazy-created conversations loaded and skip only when the hook holds this one?
// ChatWindow lazy-creation branch
setViewedConversationId(currentConversationId)
markConversationLoaded(currentConversationId)
// here
if (!force && loadedConversationIdRef.current === activeConversationId && (
sendCallbacksRef.current.isSendInFlight(activeConversationId)
|| activeLoadRef.current === null
)) { return }|
|
||
| it('should skip loaded or sending conversations unless a forced load is requested', async () => { | ||
| getMessages.mockResolvedValue(transcript('main')) | ||
| it('should load a sending conversation when another one is loaded, and skip one already loaded', async () => { |
Contributor
There was a problem hiding this comment.
This rewrite drops coverage of two still-supported behaviors: requestForcedLoad() bypassing the guard, and not refetching an already-loaded conversation (coverage confirms neither runs). The title's "skip one already loaded" isn't asserted either. Could you add these back (both pass on this branch) and rename this test?
it('should not refetch a conversation the hook already holds', async () => {
getMessages.mockResolvedValueOnce(transcript('main'))
const { result, rerender } = renderMessages()
await waitFor(() => expect(result.current.loadedConversationId).toBe('main'))
act(() => { result.current.markConversationLoaded('branch') })
rerender({ activeConversationId: 'branch' })
expect(getMessages).toHaveBeenCalledTimes(1)
})
it('should load a held conversation when a forced load is requested', async () => {
getMessages.mockResolvedValueOnce(transcript('main')).mockResolvedValueOnce(transcript('branch'))
const { result, rerender } = renderMessages()
await waitFor(() => expect(result.current.loadedConversationId).toBe('main'))
act(() => { result.current.markConversationLoaded('branch') })
act(() => { result.current.requestForcedLoad() })
rerender({ activeConversationId: 'branch' })
expect(getMessages).toHaveBeenCalledTimes(2)
expect(getMessages).toHaveBeenLastCalledWith('attack', 'branch')
})This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3662
The conversation reload guard skipped any conversation with a send in flight, even after the user had navigated away and the hook had loaded a different conversation. Returning to the sending conversation through the URL then kept the other conversation's transcript on screen with no loading state, because the in-flight send also suppresses the load-gap flag, and nothing replaced the view until the send completed.
The skip now applies only while the hook still holds the sending conversation's own view. When another conversation is loaded, returning loads fresh server state, and the existing send pipeline keeps layering its pending messages and loading indicator on top of the fetched transcript, so the displayed view stays correct while the send runs. Mounting straight into a sending conversation still skips the fetch exactly as before.
Tests and Documentation
Added a regression that loads a second conversation and returns to the sending one, asserting the transcript is fetched and displayed. It fails on main and passes with the change. One existing test pinned the old skip for a sending conversation while another was loaded and now expects the fetch, with a comment explaining why the fetch is required. The full hooks suite passes (323 tests) and tsc is clean.
No documentation change needed, so I did not run JupyText.